﻿using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;

using Warehouse.Silverlight.Core.Infrastructure;
using Warehouse.Silverlight.Core.Infrastructure.ViewModels;
using Warehouse.Silverlight.Modules.Main.Models;
using Warehouse.Silverlight.Modules.Main.Services;

namespace Warehouse.Silverlight.Modules.Main.ViewModels
{
    [Export]
    public class LoginStateViewModel : ViewModel
    {
        //private readonly IProductService _productService;
        private readonly IEventAggregator _eventAggregator;
        private bool _isLogined;

        [ImportingConstructor]
        public LoginStateViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;

            Initialize();
        }

        public string DisplayText { get; private set; }

        public bool IsLogined
        {
            get { return _isLogined; }
            set
            {
                if (_isLogined != value)
                {
                    _isLogined = value;
                    RaisePropertyChanged(() => IsLogined);
                }
            }
        }

        // Override
        protected override void Initialize()
        {
            _eventAggregator.GetEvent<LoginStateChangedEvent>().Subscribe(ChangeCurrentLoginState);
        }

        public void ChangeCurrentLoginState(bool newLoginState)
        {
            this.IsLogined = newLoginState;
        }
    }
}
